<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>日程详情</title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/mui.picker.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/schedule.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/commonality.css">
    <script src="../../js/mui.min.js"></script>
    <script src="../../js/jquery.min.js"></script>
    <script src="../../js/jquery.flexText.min.js"></script>
    <script src="../../js/vue.js"></script>
    <script src="../../js/main.js"></script>

</head>
<body>
<div id="app">
    <header class="mui-bar mui-bar-nav">
        <span class="back" @click="back"></span>
        <span class="cross" @click="close"></span>
        <h1 class="mui-title my_mui-title">日程详情</h1>
        <button id="deleteBtn" class="mui-btn mui-btn-link" @click="delete_yes" v-show="del_show">删除</button>
    </header>
    <div class="mui-content myContent" >
        <div class="title">
            <p>最后保存:{{ time|getData}}</p>
            <div class="clearFix"></div>
        </div>
        <div class="module">
            <div class="mui-input-row">
                <label>标题 :</label>
                <div class="info" v-text="obj.title"></div>
                <div class="clearFix"></div>
            </div>
            <div class="mui-input-row">
                <label>内容 :</label>
                <div class="info"  v-text="obj.message"></div>
                <div class="clearFix"></div>
            </div>
            <div class="mui-input-row">
                <label>截至时间</label>
                <div class="date" class="ui-alert" v-text="obj.deadlineTime"></div>
            </div>
        </div>
        <div class="module">
            <div class="approver ">
                <p>指定协作人 : <span>(唯一)</span></p>
                <div class="add-approver myApprover" v-for="targetUser in obj.targetUser">
                    <div >
                        <div class="approver-img">{{targetUser.userName|getHName}}</div>
                    </div>
                    <p class="add-person" v-text="targetUser.userName"></p>
                </div>
                <div style="clear:both;"></div>
            </div>
            <div class="carbonCopy " v-show="isShow">
             <p>抄送人 : </p>
                <div class="add-approver" v-for="ccUser in obj.ccListUser">
                    <div >
                        <div class="approver-img">{{ccUser.userName|getHName}}</div>
                    </div>
                    <p class="add-person" v-text="ccUser.userName"></p>
                </div>
                <div style="clear:both;"></div>
            </div>
         </div>

        <div class="module review-all">
              <div class="approver" >
                  <p>评论 : </p>
                  <div class="add-approver comment" v-for="commet in obj.commetList">
                      <div >
                          <div class="approver-img lf">{{commet.createUserName|getHName}}</div>
                      </div>
                      <div class="people_status">
                          <p class="add-person date rt" v-text="commet.createTime"></p>
                          <p class="add-person name" v-text="commet.createUserName"></p>
                          <p class="add-person isAgree add-person-content" v-text="commet.content"></p>

                      </div>
                      <div class="clearFix"></div>
                  </div>
              </div>
        </div>

        <div class="write-review-module">
            <div class="write-review">
                <button class="mui-btn mui-btn-success write-review-btn rt" @click="review">提交</button>
                <textarea class="write-review-content" v-model="obj.content" placeholder="写评论.."></textarea>
                <!--<textarea class="write-review-content lf" v-model="obj.content" placeholder="写评论..">-->

            </div>
        </div>

      <!--  <div class="footer">
            <div class="submit-btn">
                <button class="mui-btn mui-btn-primary"  v-if="type==1" :disabled="!afterDeadline || obj.status !=1" @click="finish($event)">完成1</button>
                <!--<button class="mui-btn mui-btn-primary" v-if="type==3">评论1</button>
            </div>-->
        <div class="footer" v-show="finish_show">
            <div class="submit-btn">
                <button class="mui-btn mui-btn-primary" @click="finish($event)" v-if="obj.status == 1" :disabled="afterDeadline">完成</button>
                <button class="mui-btn mui-btn-primary"  v-if="obj.status == 2" :disabled="obj.status == 2">已完成</button>
            </div>
        </div>

           <!-- <div class="submit-btn nominator-btn" v-if="type==2 && !isFinished">
                <button class="mui-btn mui-btn-primary" :disabled="afterDeadline || obj.status ==1" @click="finish($event)">完成2</button>
                <button class="mui-btn mui-btn-primary">评论2</button>
                <div class="clearFix"></div>
            </div>
            <div class="submit-btn" v-if="type == 2 && isFinished">
                <button class="mui-btn mui-btn-primary">评论3</button>
            </div>-->
        </div>
    </div>
  </div>
</body>
<script src="../../js/mui.picker.min.js"></script>
<script>
    $(function () {
        $('textarea').flexText();
        $(window).on("resize",function(){
            $(".footer").toggle();
            $(".mui-content").toggleClass("sch-content");
        });
    });
    function UrlSearch(){
        var name,value;
        var str=location.href; //取得整个地址栏
        var num=str.indexOf("?");
        str=str.substr(num+1); //取得所有参数   stringvar.substr(start [, length ]

        var arr=str.split("&"); //各个参数放到数组里
        for(var i=0;i < arr.length;i++){
            num=arr[i].indexOf("=");
            if(num>0){
                name=arr[i].substring(0,num);
                value=arr[i].substr(num+1);
                this[name]=value;
            }
        }
    }
    var Request=new UrlSearch(); //实例化

    function sendInfoToJava(name) {
        //调用android程序中的方法，并传递参数
        javascript:WebView.showInfoFromJs(name);
    }

        var app = new Vue({
            el: "#app",
            data: function () {
                return{
                    isShow:false,
                    time:"",
                    type:2,
                    loginName:"",
                    isFinished:null,
                    afterDeadline:null,//完成按钮状态，截止日期之后置灰不可用
                    //*************************************************************
                    code:0,
                    errorMsg: null,
                    obj:{
                        "zgScheduleId": 1,
                        "updateUser":"loginName",
                        "isDelete": null,
                        "status": 0,
                        "isRead": null,
                        "content": "",
                        "createUser": "username",
                        "scheduleId": 14
                    },
                    del_show: false,
                    finish_show: false
                }
            },
            filters: {
                getData:function (input) {
                   var d = new Date(input);
                   var hour = d.getHours();
                   var minutes = d.getMinutes();
                   return  hour + ':' + minutes;
               },
               getHName: function(input) {
                   if(input != null){
                       return input.slice(-2);
                   }else{
                       return '';
                   }
               }
            },
            methods: {
                back: function () {
                    var name = "back";
                    sendInfoToJava(name);
                },
                close: function () {
                    var name = "close";
                    sendInfoToJava(name);
                },
                ready: function () {
                    var this_obj = this;
                    this.obj.zgScheduleId=Request.sid == null? 108:Request.sid;
                    this.obj.updateUser=Request.loginName == null?"wangyajie":Request.loginName;
                    this_obj.loginName = Request.loginName == null?"wangyajie":Request.loginName;
                    var data={};
                    data.zgScheduleId =this.obj.zgScheduleId;
                    data.updateUser =this.obj.updateUser;
                    data.isRead=1;
                    var url = "/schedule/zgSchedule/isRead";
                    JSON.stringify(data);
                    if(typeof(Request.sid) == "undefined" || typeof(Request.loginName) == "undefined"){
                        mui.toast("请重新登录");
                    }else{
                        common_ajax(url, data, function (res) {
                            console.log(res);
                            //alert("请求成功");
                        }, function (res) {
                            //alert("请求失败");
                            mui.toast(res.errorMsg)
                        });
                    }
                    var getUrl = "/schedule/zgSchedule/" + this.obj.zgScheduleId;
                    var getData = this._data;
                    getAjax(getUrl,function (res) {
                        console.log(res);
                        getData.obj = res.obj;
                        this_obj.obj.status = res.obj.status;
                        if(isAfterDeadline(res.obj.deadlineTime)){
                            this_obj.afterDeadline = true;
                        }else{
                            this_obj.afterDeadline = false;
                        }
                        if(res.obj.ccListUser.length == 0){
                            this_obj.isShow=false;
                        }else{
                            this_obj.isShow=true;
                        }
                        for(var i=0;i<res.obj.ccListUser.length;i++){
                            if(this_obj.loginName == res.obj.ccListUser[i].receiveUser){
                                this_obj.type = 1;//抄送者浏览仅显示评论
                                this_obj.del_show = false;
                                this_obj.finish_show = false
                            }
                        }
                        if(this_obj.loginName == res.obj.createUser && this_obj.loginName == res.obj.targetUser[0].receiveUser){
                               //显示评论，删除，完成
                            this_obj.del_show = true;
                            this_obj.finish_show = true;
                        }else if(this_obj.loginName == res.obj.targetUser[0].receiveUser && this_obj.loginName != res.obj.createUser){
                              //仅显示评论，完成
                            this_obj.del_show = false;
                            this_obj.finish_show = true;
                        }else if(this_obj.loginName == res.obj.createUser && this_obj.loginName != res.obj.targetUser[0].receiveUser){
                            //   仅显示评论，删除
                            this_obj.del_show = true;
                            this_obj.finish_show = false;
                        }
                        console.log(res);
                    },function (res) {
                        alert("请求失败");
                    });
                },
                review : function () {
                    var data={};
                    data.createUser = Request.loginName;
                    data.scheduleId =this.obj.zgScheduleId;
                    if(this.obj.content == undefined){
                        mui.toast("请添加评论内容")
                    }else{
                        data.content = this.obj.content;
                        var url = "/schedule/zgSchedule/addComment";
                        if(typeof(Request.loginName) == "undefined"){
                            mui.toast("请重新登录");
                        }else {
                            common_ajax(url, data, function (res) {
                                app.ready();
                                console.log("提交成功");
                            }, function (res) {
                                console.log("提交失败");
                            })
                        }
                    }
                },
                delete_yes : function () {
                    var this_obj = this;
                    var btnArray = ['取消', '确定'];
                    mui.confirm("您确定删除本次日程", '', btnArray, function(e) {
                        if (e.index == 1) {
                           var data={};
                           data.zgScheduleId = this_obj.obj.zgScheduleId;
                           data.updateUser =this_obj.loginName;
    //                       debugger
                           data.isDelete=1;
                           var url = "/schedule/zgSchedule/update";
                           common_ajax(url,data,function (res) {
                               mui.toast("删除成功");
                                  this_obj.back();
                           },function (res) {
                               console.log("删除失败");
                           });
                        } else {
                              mui.toast("您点击了取消");
                        }
                    })

                },
                finish : function (msg) {
                    var this_obj = this;
                    this_obj.isFinished = true;
    //                debugger
                    var current = msg.currentTarget.parentNode.parentNode;
                    current.style.display="none";
                    var data={};
                    data.zgScheduleId = this.obj.zgScheduleId;
                    data.updateUser =this_obj.loginName;
                    data.status=2;
                    var url = "/schedule/zgSchedule/update";
                    common_ajaxs(url,data,function (res) {
    //                    console.log(1)
                        this_obj.back();
                    },function (res) {
                        mui.toast(res.errorMsg)
                    });
                },
                save_time: function() {
                 var this_obj = this;
                 var date = new Date();
                 this_obj.time=date;
                 return date;
               }
            }
        });
        function isAfterDeadline(Deadline) {
          var deadLine = new Date(Deadline.replace(/-/g,"/"));
          var current = new Date();
          if(current > deadLine){
              return true;
          }else{
              return false;
          }
        }
        app.ready();
        app.save_time();
        setInterval(app.save_time(),20*1000);


</script>
</html>